var app = new Vue({
    el: "#app",
    data: {
        form: {
            dist2: 3706e2,
            hkszd: 370602,   //户口所在地
            sfzh: "",      //身份证号
            lxdh: "",      //联系电话
            zwx: "",       //中文姓
            zwm: "",       //中文名
            sqlbArray: [],       //申请类别
            qwdArray: [],         //前往地
            sqlb: [],
            qwd: [],


            xczjhmGa: "",
            xczjyxqzGa: null,
            qzzlHkg: '12',   //香港签注种类
            qzzlMac: '12',   //澳门签注种类
            qzcsHkg: '0301', //香港签注次数
            qzcsMac: '0301', //澳门签注次数


            xczjhmTw: "",
            xczjyxqzTw: null,
            qzzlTwn: '2B',   //台湾签注种类
            qzcsTwn: '0601', //台湾签注次数

            sfxtkzd: '1',
            sjr: "",
            yzbm: "",
            emsdz: "",
            sjhm: ""


        },


        qzzlHkgOptions: [{key: '12', value: '团队旅游'}],
        qzzlMacOptions: [{key: '12', value: '团队旅游'}],
        qzzlTwnOptions: [{key: '25', value: '团队旅游'}, {key: '2B', value: '个人旅游'}],
        sqzjhqzOptions: [{key: '11', value: '申请证件和签注'}, {key: '10', value: '仅申请证件'}, {key: '01', value: '仅申请签注'}]
    },
    methods: {
        onGaqzChange: function (e) {

        },
        onTwqzChange: function (e) {
            if (this.form.qzzlTwn == '25' && this.form.qzcsTwn.substring(2, 4) != '01') {
                showDialog("赴台团队旅游多次签注，申请对象仅限赴台旅游组团社领队！");
            }

        },
        check: function (e) {
            if (this.validateInput()) {
                var that = this;
                // this.form.qwd = this.form.qwdArray.join(",");
                // this.form.sqlb = this.form.sqlbArray.join(",");
                alert();

                $.post("/outerApply/check", {formJson:JSON.stringify(this.form)}, function (res) {
                    if (res.result == "ok") {
                        $("#zggmtbForm").submit();
                    }
                    else if (res.result == 'tips') {
                        showTips(res.msg);
                    }
                    else if (res.result == 'error') {
                        showDialog(res.msg);
                    }
                });
            }
        },
        submit: function () {
            if (this.validateInput()) {
                $("#outerApplyForm").submit();
            }
        },
        validateInput: function () {

            //
            // this.form.qwd = this.form.qwdArray;
            // this.form.sqlb = this.form.sqlbArray;


            if (!checkIdCard(this.form.sfzh)) {
                showDialog("请输入正确的身份证号!");
                return false;
            }
            if (!checkPhone(this.form.sjhm)) {
                showDialog("请输入正确的手机号码!");
                return false;
            }
            if (!checkNull(this.form.zwm, this.form.zwx)) {
                showDialog("请输入正确的姓名!");
                return false;
            }



            if (this.form.sqlb.length == 0 ) {
                showDialog("请至少选择一项要办理的签注信息！");
                return false;
            }

            if (checkContains(this.form.sqlb, "102")) {


                if (!checkNull(this.form.xczjhmGa)) {
                    showDialog("请输入正确的往来港澳通行证号码!");
                    return false;
                }

                if (!checkNull(this.form.xczjyxqzGa)) {
                    showDialog("请选择正确的往来港澳通行证有效期!");
                    return false;
                }

                if (!checkContains(this.form.qwd, 'HKG') && !checkContains(this.form.qwd, 'MAC')) {
                    if (!checkNull(this.form.xczjhmGa)) {
                        showDialog("请填写正确的往来港澳签注信息!");
                        return false;
                    }
                }


            }

            if (checkContains(this.form.sqlb, "104")) {
                //办理证件和签注或者仅办证
                if (!checkNull(this.form.xczjhmTw)) {
                    showDialog("请输入正确的往来港澳通行证号码!");
                    return false;
                }

            }


            return true;
        }
    },
    computed: {
        formJson: function () {
            return JSON.stringify(this.form);
        },
        distOptions3: function () {
            if (this.form.dist2 == 3706e2) {
                this.form.hkszd = 370602;
            }
            else {
                for (p in distData[this.form.dist2]) {
                    this.form.hkszd = p;
                    break;
                }
            }

            return distData[this.form.dist2];
        },
        idNumber: {
            get: function () {
                return this.form.sfzh;
            },
            set: function (newValue) {
                this.form.sfzh = newValue.toUpperCase();
            }
        },
        zwx: {
            set: function (newValue) {
                this.form.ywx = convertPinYin(newValue);

                if ((this.form.zwx + this.form.zwm) == this.form.sjr) {
                    this.form.sjr = newValue + this.form.zwm;
                }
                this.form.zwx = newValue;
            },
            get: function () {
                return this.form.zwx;
            }
        },
        zwm: {
            set: function (newValue) {
                this.form.ywm = convertPinYin(newValue);
                if ((this.form.zwx + this.form.zwm) == this.form.sjr) {
                    this.form.sjr = this.form.zwx + newValue;
                }
                this.form.zwm = newValue;
            },
            get: function () {
                return this.form.zwm;
            }
        },
        lxdh: {
            set: function (newValue) {
                if (this.form.lxdh == this.form.sjhm) {
                    this.form.sjhm = newValue;
                }
                this.form.lxdh = newValue;
            },
            get: function () {
                return this.form.lxdh;
            }
        },


        gazlDisplay: function () {
            if (checkContains(this.form.sqlb, '102')) {
                //办理证件且办证类型不为首次申领
                return false;

            }
            return true;
        },
        xgqzDisplay: function () {
            if (checkContains(this.form.sqlb, '102') && checkContains(this.form.qwd, 'HKG')) {
                return false;
            }

            return true;
        },
        amqzDisplay: function () {
            if (checkContains(this.form.sqlb, '102') && checkContains(this.form.qwd, 'MAC')) {
                return false;
            }

            return true;
        },

        twzlDisplay: function () {

            if (checkContains(this.form.sqlb, '104')) {
                //办理证件且办证类型不为首次申领
                return false;

            }
            return true;
        },
        twqzDisplay: function () {

            if (checkContains(this.form.sqlb, '104')) {

                if (this.form.sqzjhqzTw == '11' || this.form.sqzjhqzTw == '01') {
                    return false;
                }

            }
            return true;
        },
        qzcsHkgOptions: function () {
            return [{key: '0301', value: '3个月一次'}, {key: '0302', value: '3个月二次'}, {key: '1201', value: '1年一次'}, {key: '1202', value: '1年二次'}];
        },
        qzcsMacOptions: function () {
            return [{key: '0301', value: '3个月一次'}, {key: '1201', value: '1年一次'}];

        },
        qzcsTwnOptions: function () {

            var result = [];
            switch (this.form.qzzlTwn) {

                case '25'://团队旅游
                    result = [{key: '0601', value: '6个月一次'}, {key: '1299', value: '一年多次'}];
                    break;
                case '2B'://个人旅游
                    result = [{key: '0601', value: '6个月一次'}];
                    break;
            }
            this.form.qzcsTwn = result[0].key;
            return result;
        },


    }
});


$(document).ready(function () {

});

function showTips(tips) {
    $("#tipsContent").text(tips);
    $("#iosDialog1").fadeIn(200);
}

function hideDialog1() {
    $("#iosDialog1").fadeOut(200);
}

function submitForm() {
    app.submit();
    hideDialog1();
}